$(function() {

    var ED_D = ST_D = iG.getYear() + "-" + iG.getMonth() + "-" + iG.getDay();
    //$('#startDate').text("2016-10-16");
    //$('#endDate').text("2017-06-23");
    $("#startDate").on("tap", getStratDate);
    $("#endDate").on("tap", getEndDate);

    //获取开始时间
    function getStratDate() {
      //   IC.talkingDataCount("集团客户", "0010");
        var datese = {
            year : iG.getYear(),
            month : iG.getMonth(),
            day : iG.getDay()
        }
        $('#startDate').attr('ST_D', JSON.stringify(datese));

        var that = $(this);
        var date = JSON.parse($("#startDate").attr("ST_D"));
        uexControl.openDatePicker(date.year, date.month, date.day);
        uexControl.cbOpenDatePicker = function(opCode, dataType, data) {
        var endD = $('.endD').text();
        console.log(endD);
            if (dataType == 1) {
                data = eval('(' + data + ')');

            }
            if (ED_D.split("-")[0] > data.year | (ED_D.split("-")[0] == data.year & ED_D.split("-")[1] > data.month) | (ED_D.split("-")[0] == data.year & ED_D.split("-")[1] == data.month & ED_D.split("-")[2] >= data.day)) {
                setDate_s(that, data.year, data.month, data.day);
                ST_D = data.year + '-' + data.month + '-' + data.day;
              
            }else if(endD === '请选择日期'){
                
                 setDate_s(that, data.year, data.month, data.day);
                ST_D = data.year + '-' + data.month + '-' + data.day;  
            }else{
                appcan.window.openToast('开始日期不能大于结束日期',3000,5,0);
                return;
            } 
           
        }
        setDate_s = function(elem, year, month, day) {

            var month = Number(month);
            var day = Number(day);
            var months,
                days;
            months = month >= 10 ? "" + month : "0" + month;
            days = day >= 10 ? "" + day : "0" + day;
            var json = {
                "year" : year,
                "month" : months,
                "day" : days,
            };
            $("#startDate").attr("ST_date", year + "-" + months + "-" + days);
            $("#startDate").text(year + "-" + months + "-" + days);
           // console.log(year + "-" + months + "-" + days);
        };

    }

    // 获取结束时间
    function getEndDate() {
       //  IC.talkingDataCount("集团客户", "0010");
        var datase = {
            year : iG.getYear(),
            month : iG.getMonth(),
            day : iG.getDay()
        }
        $("#endDate").attr("ED_D", JSON.stringify(datase));
        var that = $(this);
        var date = JSON.parse($("#endDate").attr("ED_D"))
        uexControl.openDatePicker(date.year, date.month, date.day);
        uexControl.cbOpenDatePicker = function(opCode, dataType, data) {
            if (dataType == 1) {
                data = eval('(' + data + ')');
            }
            if (ST_D.split("-")[0] > data.year | (ST_D.split("-")[0] == data.year & ST_D.split("-")[1] > data.month) | (ST_D.split("-")[0] == data.year & ST_D.split("-")[1] == data.month & ST_D.split("-")[2] > data.day)) {
                appcan.window.openToast("结束时间不能小于开始时间", 3000, 5, 0);
                return;
            } else {
                setDate_s(that, data.year, data.month, data.day);
                ED_D = data.year + "-" + data.month + "-" + data.day;
            }
            //IC.talkingDataCount("集团客户", "0010");
        }
        setDate_s = function(elem, year, month, day) {
            var month = Number(month);
            var day = Number(day);
            var months,
                days;
            months = month >= 10 ? "" + month : "0" + month;
            days = day >= 10 ? "" + day : "0" + day;
            var json = {
                "year" : year,
                "month" : months,
                "day" : days,
            };
            $("#endDate").attr("ED_date", year + "-" + months + "-" + days);
            $("#endDate").text(year + "-" + months + "-" + days);
        };
    }

});


